<template>
    <div id="app">
        <!-- 登录 -->
        <div class="dh_xgj-register" v-if="!login.state">
            <form action="" class="d_x-reg-form">

                <h3>校管家</h3>

                <div class="d_x-r-f-text">
                    <i class="dx-rft-log unameicon" aria-hidden="true"></i>
                    <input id="int-name" tyep="text" max="18" min="6" name="uname" placeholder="账号" v-model="login.uname"/>
                    <label for="int-name" class="dx-rft-label"></label>
                </div>

                <div class="d_x-r-f-text">
                    <i class="dx-rft-log pwdicon" aria-hidden="true"></i>
                    <input id="int-pwd" :type="typepwd" max="18" min="6" name="pwd" placeholder="密码" v-model="login.pwd" autocomplete="off" @input="examine" />
                    <i v-if="examinestate" @click="checkpwd" class="dx-rft-eye"></i>
                    <label for="int-pwd" class="dx-rft-label"></label>
                </div>

                
                <div class="d_x-r-f-btn">
                    <span>{{login.text}}</span>
                </div>

                <el-button class="dx-rft-btn" slot="reference" @click="register" @keyup.13.native="register">登录</el-button>

            </form>
        </div>
        <!-- 
            后台数据
         -->
        <div class="dh_xgj-content" v-else>
            <!-- 侧边导航栏 -->
            <div class="d_x-c-navigation">
				  
                <el-menu :default-active="$route.path" router @select="handleSelect" class="el-menu-vertical-demo">
                    
                    <el-menu-item :index="item.link.toString()" v-for="(item,indexa) in navioption" :key="indexa"  @click="navBar(item,indexa)">
                        <span slot="title" :class="(item.name.length === 3 ? 'ws24' : '')">{{item.name}}</span>
                    </el-menu-item>	

                </el-menu>
                
            </div>

            <!-- 数据部分 -->
            <div class="d_x-c-details">

                <div class="d_x-c-d-title"><h1>校管家后台</h1></div>

                <!-- 数据内容，使用路由跳转 -->
                <div class="d_x-c-d-details"><router-view></router-view></div>

            </div>

        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            // 登录的账号密码数组
            login:{uname:'',pwd:'',state:false,text:''},
            //侧边栏的数组
            navioption:[											
				{id:0,name:"员工管理",link: '/'},
				{id:1,name:"信息详情",link: '/details'},
				{id:2,name:"通 知",link: '/inform'},
            ],
            examinestate:false,
            typepwd: 'password'
        }
    },
    methods: {
        // 登录按钮
        register(){
            const that = this;
            let axios = require('axios');
            let data = {name:that.login.uname,password:that.login.pwd}
            let updata = JSON.stringify(data)
            var timeId;
            axios({
                method: 'post',
                url: '/api/api/dh_school/b_login.php',
                headers: { "Content-Type": "appliction/JSON" },
                data: updata
            })
            .then( resp=> {
                // console.log(resp)
                let data = resp.data.data
                if(data.namestatus != 0 && data.passwordstatus !=0){
                    that.login.text = "验证成功"
                    that.login.state = true;
                    sessionStorage.setItem('dh_xgj_login', JSON.stringify(that.login))
                }else{
                    that.login.text = "您所输入的账号或密码不正确"
                    window.clearInterval(timeId);
                    timeId = window.setTimeout(() => {
                        that.login.text = ''
                    },3000)
                }
            })
            .catch( err=> { 
                // console.log(err)
            })
        },
        // 密码框的输入事件
        examine(){
            const that = this;
            that.examinestate = true
            if(that.login.pwd === ''){
                that.examinestate = false
            }
        },
        // 查看密码
        checkpwd(){
            const that = this;
            if(that.typepwd === ''){
                that.typepwd = 'password'
            }else{
                that.typepwd = ''
            }
        },
        // 侧边栏函数
        handleSelect(key, keyPath) {},
        // 侧边栏函数
        navBar(item,indexa){
            // console.log(this.navioption[1].name.length)
        }
    },
    computed: {},
    watch: {},
    created() {
        const that = this;
        that.activerouter = window.location.pathname;
		// console.log(this.activerouter)
		//在页面加载时读取sessionStorage里的状态信息
		if (sessionStorage.getItem("dh_xgj_login")) {
			that.login = JSON.parse(sessionStorage.getItem("dh_xgj_login"))
		}
		//用事件句柄监听，在页面刷新时将vuex里的信息保存到sessionStorage里
		// console.log(this.login.checked)
		if(that.login.checked === true){
			// console.log("成功运行")
			window.addEventListener("beforeunload", () => {
				sessionStorage.setItem("dh_xgj_login", JSON.stringify(this.login));
			});
        }else{return}
        
    },
    mounted() {},
    beforeCreate() {},
    beforeMount() {},
    beforeUpdate() {},
    updated() {},
    beforeDestroy() {},
    destroyed() {},
    activated() {},
}
</script>

<style>
    button{
        outline: none;
        border: 0;
    }

    #app {
        min-width: 1024px;
        /* min-height: 937px; */
        min-height: 100vh;
        font-family: Helvetica, sans-serif;
        text-align: center;
    }
    a{
        text-decoration:none
    }
    /* 登录跟成功登录的页面效果一样 */
    .dh_xgj-register,.dh_xgj-content{
        display: flex;
        justify-content: center;
        /* min-height: 937px; */
        min-height: 100vh;
        background: url(assets/bgcimg.jpg) no-repeat;
        background-size: 100% 100%;
    }
    /* 登录框 */
    .d_x-reg-form{
        width: 300px;
        height: 300px;
        margin: auto;
        padding: 40px 80px;
		background-color: rgba(218, 199, 199, 0.3);
		border-radius: 10px;
		box-shadow: 1px 1px 8px 2px #000000;
    }
    .d_x-reg-form>h3{
        font-size: 18px;
        font-weight: 600;
        /* color: #0087c5; */
        color: white;
		text-shadow: 1px 1px 2px #000000;
    }
    /* 账号和密码 */
    .d_x-r-f-text{
        overflow: hidden;
        position: relative;
        display: flex;
        align-items: center;
        height: 40px;
        margin-top:30px;
        background-color: #fff;
        border-radius: 8px;
    }
    /* 图标 */
    .dx-rft-log{
        display: inline-block;
		width: 25px;
		height: 25px;
		margin: 0 5px;
    }
    div.d_x-r-f-text>i.unameicon{
        background: url(assets/uname.png) no-repeat 100% 100%;
    }
    div.d_x-r-f-text>i.pwdicon{
        background: url(assets/pwd.png) no-repeat 100% 100%;
    }
    /* 查看密码的图标 */
    .dx-rft-eye{
        z-index: 10000;
        position: relative;
        width: 20px;
		height: 20px;
		margin: 0 5px;
        background: url(assets/eye.png) no-repeat 100% 100%;
        background-size: 100% 100%;
    }
    /* 输入框 */
    .d_x-r-f-text>input{
        width: calc(100% - 69px);
        color: #0087c5;
		border: 0;
		outline: none;
    }
    input:focus,
	input:focus+i {
		color: #0087c5;
	}
    input:focus~.dx-rft-label {
		border: 1px solid #0087c5;
	}
    .dx-rft-label{
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		margin: 0;
		border: 1px solid rgb(187, 187, 187);
		border-radius: 5px;
	}
    /* 登录验证的提示信息 */
    .d_x-r-f-btn{
        text-align: left;
        font-size: 14px;
        height: 21px;
        text-shadow: 1px 1px 2px rgb(0, 0, 0);
        margin: 20px 0;
        color: #ffff;
        border: 1px solid transparent;
    }
    /* 确认按钮 */
    form.d_x-reg-form>.el-button{
        width: 100%;
        height: 40px;
        padding: 0;
        font-size: 18px;
        color: black;
        border: 0;
        border-radius: 8px;
    }

    /* 后台数据样式   侧边栏*/
    .d_x-c-navigation{
        width: 130px;
        min-height: calc(100vh - 56px);
        padding-top: 56px;
    }
    div.d_x-c-navigation>ul.el-menu{
        background-color: transparent;
        border-right: 0;
    }
    /* 导航栏选中状态 */
    div>.d_x-c-navigation>ul.el-menu>.el-menu-item.is-active {
		background-color: #ffffffd2 !important;
		color: rgb(0, 110, 255);
        font-weight: 600;
        box-shadow: 1px 1px 10px rgb(95, 95, 95);
	}
    li.el-menu-item:hover{
        background-color: transparent;
    }
    li.el-menu-item{
        color: white;
    }
    /* 数据部分的样式 */
    .d_x-c-details{
        width: calc(100% - 130px);
        min-height: 100%;
    }
    .d_x-c-d-title{
        position: relative;
        z-index: 1000;
        height: 56px;
        line-height: 56px;
        /* color: #0087c5; */
        color: white;
        font-weight: 600;
        font-size: 22px;
        text-shadow: 1px 1px 1px rgb(82, 82, 82);
        box-shadow: 11px 1px 10px rgb(12, 12, 12);
    }
    /* 列表数据 */
    .d_x-c-d-details{
        height: calc(100% - 56px);
        padding: 30px;
        background-color: rgb(240, 240, 240);
        box-sizing: border-box;
    }
</style>
